#include <bits/stdc++.h>
using namespace std;

const int N = 2e5+5;
int n, a[N];

int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> a[i];
        int ans = 0;
        for (int i = 0; i < 1 << n; i++) {
            int sum = 0;
            for (int j = 1; j <= n; j++)
                for (int k = j - 1; k >= 1; k--)
                    if (((1 << (j - 1)) & i) && ((1 << (k - 1)) & i) || !((1 << (j - 1)) & i) && !((1 << (k - 1)) & i)) {
                        if (a[j] == a[k]) sum += a[j];
                        break;
                    }
            ans = max(ans, sum);
        }
        cout << ans << "\n";
    }
    return 0;
}